import {fetchListAll as fetchSubjectListAll} from '@/api/subject'
import {fetchListAll as fetchTypeListAll} from '@/api/type'
import {fetchListAll as fetchLevelListAll} from '@/api/level'



const questiondata = {
  state: {
    subjectOptions: [],  //所有学科
    allLevelList: [],  //所有阶段
    allTypeOptions:[] ,//所有题型
    
    //做题情况的选项
    testStatusOptions: [
          {
          value: 0,
          label: '没做过'
          },
          {
          value: 1,
          label: '错1次'
          },
          {
          value: 2,
          label: '错2次以上'
          },
          {
          value: 3,
          label: '做对了（但之前有错）'
          },
          {
          value: 4,
          label: '1次做对了'
     }],
    //审核状态的选项
    verifyStatusOptions: [
          {
          value: 1,
          label: '审核通过'
          },
          {
          value: 0,
          label: '未审核'
     	}],
    //有效状态的选项
    validStatusOptions: [{
          value: 1,
          label: '有效'
          },{
          value: 0,
          label: '无效'
    }],
   
    //难度状态的选项
    difStatusOptions: [{
          value: 5,
          label: '5-竞赛'
          },
          {
            value: 4,
            label: '4-拓展'
          }, {
            value: 3,
            label: '3-综合应用'
          },
          {
            value: 2,
            label: '2-简单应用'
          }, {
            value: 1,
            label: '1-入门'
     }],
         //推荐状态的选项
    starStatusOptions: [{
          value: 5,
          label: '5星'
          },
          {
            value: 4,
            label: '4星'
          }, {
            value: 3,
            label: '3星'
          },
          {
            value: 2,
            label: '2星'
          }, {
            value: 1,
            label: '1星'
    }]

  },
  mutations: {
    SET_SUBJECTOPTIONS: (state, subjectOptions) => {
      state.subjectOptions = subjectOptions
    },
    SET_ALLTYPEOPTIONS: (state, allTypeOptions) => {
      state.allTypeOptions = allTypeOptions
    },
    SET_LEVELLIST: (state, allLevelList) => {
      state.allLevelList = allLevelList
    },

    
   

    
  },


  actions: {
    

  	//获得所有学科列表
    GetSubjectList({commit,state}) {
    	return new Promise((resolve,reject)=>{
    		fetchSubjectListAll().then(response=>{
    			let subjectOptions = [];
		        let subjectList = response.data.list;
            if(subjectList===null) return
		        for (let i = 0; i < subjectList.length; i++) {
		            subjectOptions.push({label: subjectList[i].name, value: subjectList[i].id});
          		}
          		commit('SET_SUBJECTOPTIONS', subjectOptions)

    		}).catch(error=>{
    			reject(error)
    		})

    	})
       
    },

    //获得所有阶段
    GetLevelListAll({commit,state}) {
      return new Promise((resolve,reject)=>{
        fetchLevelListAll().then(response=>{
          let levelOptions = [];
          let levelList = response.data.list;
       
          commit('SET_LEVELLIST', levelList)
          
           

        }).catch(error=>{
          reject(error)
        })

      })
       
    },

    GetTypeListAll({commit,state}){
      return new Promise((resolve,reject)=>{
        fetchTypeListAll().then(response => {
          let allTypeOptions = [];
          let allTypeList = response.data.list;
          if(allTypeList===null) return
          for (let i = 0; i < allTypeList.length; i++) {
            allTypeOptions.push({label: allTypeList[i].name, value: allTypeList[i].id});
          }
          commit('SET_ALLTYPEOPTIONS', allTypeOptions)
        }).catch(error=>{
          reject(error)
        });
      })
    }

  	
  }
};
export default questiondata;
